
import 'package:elevator/model/build_info.dart';
import 'package:elevator/model/lift_info.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

import '../../../../../../../../utils/eventbus.dart';

class SecondLogic extends GetxController {

  BuildInfo buildInfo;
  LiftInfo liftInfo;

  var pus = "".obs;
  var puw = "".obs;

  var dls = "".obs;
  var lds = "".obs;
  var pulse = "".obs;

  SecondLogic(this.buildInfo, this.liftInfo){
    if(null!=liftInfo.pusInfo){
      pus.value = liftInfo.pusInfo!.pusLName;
    }

    if(null!=liftInfo.puwInfo){
      puw.value = liftInfo.puwInfo!.pumLName;
    }

    if(null!=liftInfo.dls){
      dls.value = liftInfo.dls!;
    }

    if(null!=liftInfo.lds){
      lds.value = liftInfo.lds!;
    }

    if(null!=liftInfo.pulse){
      pulse.value = liftInfo.pulse!;
    }

  }

  @override
  void onReady() {
    super.onReady();
  }

  busCallback(arg){
    liftInfo = arg;
    if(null!=liftInfo.pusInfo){
      pus.value = liftInfo.pusInfo!.pusLName;
    }else{
      pus.value = "";
    }
    pus.refresh();
    if(null!=liftInfo.puwInfo){
      puw.value = liftInfo.puwInfo!.pumLName;
    }else{
      puw.value = "";
    }
    puw.refresh();
  }

  @override
  void onClose() {
    debugPrint("SecondLogic:onClose:liftInfo_${buildInfo.buildId}_${liftInfo.order}");
    super.onClose();
  }

  void register(){
    bus.on('${bus.liftInfo_Key}${buildInfo.buildId}_${liftInfo.order}', busCallback);
  }

  void unregister(){
    debugPrint("SecondLogic:unregister:liftInfo_${buildInfo.buildId}_${liftInfo.order}");
    bus.off('${bus.liftInfo_Key}${buildInfo.buildId}_${liftInfo.order}', busCallback);
  }

}
